#pragma once

#include <string>
#include "CJsonObject.hpp"
#include <sstream>

using namespace std;
using namespace neb;

struct SdpMsg
{
    string type = "";
    string sdp = "";

    string toJson()
    {
        stringstream sstream;
        sstream << "{";
        sstream << R"("type":")" << type << R"(",)";
        sstream << R"("sdp":")" << sdp << R"(")";
        sstream << "}";
        return sstream.str();
    }

    void getJsonObj(CJsonObject &sdpObj)
    {
        sdpObj.Add("type", type);
        sdpObj.Add("sdp", sdp);
    }
};

struct SignalOrderInfo
{
    string orderType = "";
    string roomId = "";
    string userId = "";
    string userName = "";
    int64_t fd = -1;
    SdpMsg sdpInfo; // when order type is "createOffer"
    string candidate = "";

    string toJson()
    {
        CJsonObject jsonObj;
        jsonObj.Add("orderType", orderType);
        jsonObj.Add("roomId", roomId);
        jsonObj.Add("userId", userId);
        jsonObj.Add("userName", userName);
        if (orderType == "createOffer")
        {
            CJsonObject sdpObj;
            sdpInfo.getJsonObj(sdpObj);
            jsonObj.Add("msg", sdpObj);
        }
        return jsonObj.ToString();
    }
};

